<?php

class NewsAction extends BaseAction {

    public function index() {
        $News = M('News');
        $where_map = array();

        $cid = $_GET['c'];
        if($cid){
            $where_map['cid'] = $cid;
        }

        $firstRow = 0;
        $listRows = 20;
        $page = $_GET['p'];
        if(is_numeric($page)){
            $firstRow = ($page-1)*20;
            $listRows = $page*20;
        }

        $list = $News->where($where_map)->order('id')->limit("$firstRow , $listRows")->select();
        $count = count($list);
        import("ORG.Util.Page");       //载入分页类
        $page = new Page($count, 20);
        $showPage = $page->show();
        $this->assign("page", $showPage);
        $this->assign("list", D("News")->listNews($page->firstRow, $page->listRows));
        $this->display();
    }

}